<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Activity_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	/*
	 * 得到首单活动信息
	 */
	public function find_first_activity(){
		$this->db->select('t_activity.id,t_activity.content,t_activity.full,t_activity.productid,t_product.name,t_activity.amount,t_activity.state');
		$this->db->from('t_activity');
		$this->db->join('t_product', 't_product.id = t_activity.productid','left');
		$this->db->where("t_activity.type", 1);
		$query=$this->db->get();		
		return $query->row_array();
	}
	/*
	 * 得到启用的首单活动信息
	 */
	public function find_valid_first_activity(){
		$this->db->select('t_activity.full,t_activity.productid,t_product.price,t_activity.amount');
		$this->db->from('t_activity');
		$this->db->join('t_product', 't_product.id = t_activity.productid','left');
		$this->db->where("t_activity.type", 1);
		$this->db->where("state", 0);
		$query=$this->db->get();		
		return $query->row_array();
	}
	/*
	 * 更新活动信息
	 */
	public function update($id,$activity){
		$this->db->where('id', $id);
		$this->db->update('t_activity', $activity);
		return $this->db->affected_rows()>0;
	}
}